package com.whnk.job.task;

import java.sql.CallableStatement;
import java.sql.SQLException;

import com.whnk.common.core.utils.DateUtils;
import com.whnk.common.core.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component("subDemoTask01")
public class SubDemoTask01 extends BaseTask {
    private final Logger logger = LoggerFactory.getLogger(SubDemoTask01.class);

    @Autowired
    LoadSrcDataService loadSrcDataService;

    private String indexCode = "";

    private String dateString = "";
    /**
     * 定时任务程序入口
     * @Title: start
     * @Description: 模拟数据文件导入临时指标数据表，然后调用模型M001配置，调用存储过程P_AUTO_MODEL9完成
     *                汇总指标数据
     * @param: @param param
     * @return: void
     * @throws
     */
    public void start(String modelId) {
    	loadSrcDataService.init();
    //	String fileName="d:\\src_t_index_info.txt";

    	//String fileName=param;
    	//1：导入数据文件到临时指标数据表
        logger.info("导入数据文件到临时指标数据表");
    	//loadSrcDataService.doLoad(fileName);
    	//2：进行模型处理，完成汇总指标数据生成
        logger.info("进行模型处理，完成汇总指标数据生成");
        doModelScript(modelId);
        loadSrcDataService.releaseConnection();
    }

    public void start(String modelId,String indexCode,String dateString) {
        loadSrcDataService.init();
        //	String fileName="d:\\src_t_index_info.txt";

        /*String fileName=param;
        //1：导入数据文件到临时指标数据表
        if(StringUtils.isNotEmpty(fileName)){
            logger.info("导入数据文件到临时指标数据表");
            loadSrcDataService.doLoad(fileName);
        }*/
        //2：进行模型处理，完成汇总指标数据生成
        logger.info("进行模型处理，完成汇总指标数据生成");
        this.indexCode = indexCode;
        this.dateString = dateString;
        doModelScript(modelId);
        loadSrcDataService.releaseConnection();
    }

    /**
     * 存储过程参数样式
     */
    @Override
    protected String getProcedureInfo() {
        logger.info("~~~~~getProcedureInfo01~~~~");
//        return "{call " + procedureName + "(?,?,?)}";
        return "{call " + procedureName + "(?,?)}";
    }

    /**
     * 存储过程参数传递
     */
    @Override
    protected void setInAndOutParam(CallableStatement csInAndOut) throws SQLException {
        csInAndOut.setString(1, indexCode);
        csInAndOut.setString(2, dateString);
//        csInAndOut.setString(3, "@tt");
    }

    /**
     * 存储过程返回结果处理
     */
    @Override
    protected void getResultInfo(CallableStatement csInAndOut) throws SQLException {
        logger.info("~~~~~subDemoTask01~~~~");

//        logger.info("返回参数" + csInAndOut.getString(3));
  //      logger.info("返回参数" + csInAndOut.getString("model_script_out"));
    }

    @Override
    protected boolean readExecutorResult() {
        logger.info("~~~~~subDemoTask01--需要获取结果时，设置为true~~~~");
        return true;
    }


}
